package com.example.testproj.http;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @des:
 * @author: 芮勤
 * @date: 2019/6/23 11:50
 * @see {@link }
 */
public abstract class HttpEntry {
    public static final String splitString=""+(char)13+(char)10;

    protected String method;
    protected String path;
    protected String httpVersion;
    protected String body="";

    private HashMap<String,String> headers ;

    public HttpEntry() {
        headers=new HashMap();
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getHttpVersion() {
        return httpVersion;
    }

    public void setHttpVersion(String httpVersion) {
        this.httpVersion = httpVersion;
    }

    public String getHost() {
        return headers.get("Host");
    }

    public void setHost(String host) {
        headers.put("Host",host);
    }

    public String getUserAgent() {
        return headers.get("User-Agent");
    }

    public void setUserAgent(String userAgent) {
        headers.put("User-Agent",userAgent);
    }

    public String getAccept() {
        return headers.get("Accept");
    }

    public void setAccept(String accept) {
        headers.put("Accept",accept);
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public Set<Map.Entry<String, String>> getHeaders() {

        return headers.entrySet();
    }

    public void setHeaders(Set<Map.Entry<String, String>> headerSet) {
        for (Map.Entry<String, String> bean: headerSet){
            headers.put(bean.getKey(),bean.getValue());
        }
    }

    public void addHeader(String key, String value) {
        headers.put(key, value);
    }

    public void removeHeader(String key) {
        headers.remove(key);
    }

    @Override
    public String toString() {
        return "HttpEntry{" +
                "method='" + method + '\'' +
                ", path='" + path + '\'' +
                ", httpVersion='" + httpVersion + '\'' +
                ", headers=" + headers +
                '}';
    }
}
